/**
 * @Author：ming
 * @Date：2023/9/26 4:42 PM
 * @Filename：Lc230
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 */
public class Lc230 {
    public int kthSmallest(TreeNode root, int k) {
        ArrayList<Integer> list = new ArrayList<>();
        look(root,list);
        int minK = 0;
        int i = 0;
        for (Integer num : list) {
            i++;
            if(i==k){
                minK = num;
            }
        }


        return minK;
    }

    public static void look(TreeNode root, List l){
        if(root.left!=null){
            look(root.left,l);
        }
        l.add(root.val);

        if(root.right!=null){
            look(root.right,l);
        }
    }
}
